package com.yunti.springboot.vo.res;

import com.yunti.springboot.po.Score;
import com.yunti.springboot.vo.req.PageReq;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;

/**
 * @author Administrator
 */
@Data
public class ScoreCollectRes {
    private Integer stuId;
    private String stuName;
    private String className;
    private Integer classId;
    private String stuNo;
    private Integer sex;
    private Integer year;
    List<Sub>subs;
    //科目-项目（选修、必修）
    @Data
    public static class Sub{
        Integer electiveId;
        String subName;
        Integer subId;
        Integer type;
        Integer semester;
        Integer year;
        BigDecimal total;
        String unit;
        List<Item>items;
        List<Score>scoreList;
        private Score finalScore;
        public void setScoreList(List<Score> scoreList) {
            this.scoreList = scoreList;
            this.scoreList.stream().max(new Comparator<Score>() {
                @Override
                public int compare(Score o1, Score o2) {
                    Double score1 = Double.MIN_NORMAL;
                    Double score2 = Double.MIN_NORMAL;
                    if(o1.getConversionScore()!=null){
                        score1 = o1.getConversionScore().doubleValue();
                    }
                    if(o2.getConversionScore()!=null){
                        score2 = o2.getConversionScore().doubleValue();
                    }
                    return Double.compare(score1, score2);
                }
            }).ifPresent(finalScore -> {
                this.finalScore = finalScore;
            });
        }
    }
    //小项
    @Data
    public static class Item{
        String itemName;
        Integer itemNo;
        String unit;
        BigDecimal score;
        List<Score> scoreList;
        private Score finalScore;
        public void setScoreList(List<Score> scoreList) {
            this.scoreList = scoreList;
            this.scoreList.stream().max(new Comparator<Score>() {
                @Override
                public int compare(Score o1, Score o2) {
                    Double score1 = Double.MIN_NORMAL;
                    Double score2 = Double.MIN_NORMAL;
                    if(o1.getConversionScore()!=null){
                        score1 = o1.getConversionScore().doubleValue();
                    }
                    if(o2.getConversionScore()!=null){
                        score2 = o2.getConversionScore().doubleValue();
                    }
                    return Double.compare(score1, score2);
                }
            }).ifPresent(finalScore -> {
                this.finalScore = finalScore;
            });
        }
    }


}
